#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include<QHash>
#include"peopleitem.h"
#include"addpeople.h"
#include<QTcpSocket>
#include"peoplemes.h"
QT_BEGIN_NAMESPACE
namespace Ui {
class Widget;
}
QT_END_NAMESPACE
//客户端协议
//申请添加好友时:infotype:addpeople;exist:no;/exist:yes;image:path
//接收服务端发来的信息时:infotype:sendmes;sender:name;date:...;image:...;contend-type:...;contend:...;
class Widget : public QWidget
{
    Q_OBJECT

public:
    enum InfoType{ADDPEOPLE,SENDMES};
    Widget(QTcpSocket* tso=nullptr,QString name="",QPixmap pm=QPixmap(""));
    ~Widget();
    QString cur_peopleid=""; //当前聊天对象ID
    QString myname;    //以客户端名字作用标识符
    PeopleItem* cur_item;
    QPixmap mypm;
    addPeople* addpeople;
    QHash<int,PeopleItem*> peopleitemsSearch;
    QHash<QString,PeopleItem*> peopleitems;
    QHash<QString,PeopleItem*>peopleitemsName;
    int nextpeopleitem_row=0;
    QTcpSocket* ts;
public:
    void init(QTcpSocket* tso,QString name,QPixmap pm);
    void addPeopleItem(QString name,QPixmap pm);
    void ConnectSingal();
    void DealMySendMes(QString mes);
    void ChangeCurPeopleItem(int row);
    void ReceiverPeopleMes(PeopleItem* pi,QString contend_type,QVariant contend,QString time,QPixmap pm);
    QString ProcessSendMes(QString mes);
public:
    void SetAddpeopleForm(QString* mes,const QString& addedpeople);
//infotype:sendmes;sender:name;receiver:name;date:time;contend-type:...;contend:...;;    ---定义发送消息格式
    void SetSendMesForm(QString*mes,QString receiver,QString time,QString contend_type,QVariant contend);
    InfoType ConfirmInfoType(const QString& str,QString* mes);
    void GainAddPeopleMes(QString info,QString*addedpeople,bool* exist,QString* image);//当信息格式为Addpeople时获取消息相关信息
    void GainSendMes(QString info,QString*sender,QString* date_time,QString* image,QString* contend_type,QVariant*contend); //当信息格式为SendMes时获取消息相关数据
public:




private slots:
    void on_mesbtn_clicked();

    void on_addPeoBtn_2_clicked();

    void on_pushButton_clicked();

    void on_peoListWidget_currentRowChanged(int currentRow);

private:
    Ui::Widget *ui;
};
#endif // WIDGET_H
